﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace SubManager.Win
{
    public partial class ServerListForm : Form
    {
        public ServerListForm()
        {
            InitializeComponent();

            _lsvServers.Items.AddRange(
                new ListViewItem[]{
                new ListViewItem("SERVER01"),
                new ListViewItem("CHENYUANYU"),
                new ListViewItem("VMSERVER")
                });
        }

        #region Event Handlers
        private void ViewSelected(object sender, EventArgs e)
        {
            if (this._cbxViews.SelectedItem != null)
            {
                if (this._cbxViews.SelectedItem.ToString().Equals(View.Details.ToString()))
                    this._lsvServers.View = View.Details;
                else if (this._cbxViews.SelectedItem.ToString().Equals(View.LargeIcon.ToString()))
                    this._lsvServers.View = View.LargeIcon;
                else if (this._cbxViews.SelectedItem.ToString().Equals(View.List.ToString()))
                    this._lsvServers.View = View.List;
                else if (this._cbxViews.SelectedItem.ToString().Equals(View.SmallIcon.ToString()))
                    this._lsvServers.View = View.SmallIcon;
                else if (this._cbxViews.SelectedItem.ToString().Equals(View.Tile.ToString()))
                    this._lsvServers.View = View.Tile;
            }
        }
        
        private void ServerListForm_Load(object sender, EventArgs e)
        {
            // Detail view.
            this._cbxViews.SelectedIndex = 1;
        }

        private void OnOK(object sender, EventArgs e)
        {
            _selectedServerIP = "";
            _selectedServerName = _cbxViews.SelectedItem.ToString();
            _autoConnect = _ckbAutoConn.Checked;

            this.DialogResult = DialogResult.OK;
        }

        private void OnCancel(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        #endregion

        private bool _autoConnect = false;
        /// <summary>
        /// Auto Connect to selected server.
        /// </summary>
        public bool AutoConnect
        {
            get { return _autoConnect; }
            set { _autoConnect = value; }
        }
        private string _selectedServerName = "";
        /// <summary>
        /// Selected server name.
        /// </summary>
        public string SelectedServerName
        {
            get { return _selectedServerName; }
            set { _selectedServerName = value; }
        }
        private string _selectedServerIP = "";
        /// <summary>
        /// Selected server IP.
        /// </summary>
        public string SelectedServerIP
        {
            get { return _selectedServerIP; }
            set { _selectedServerIP = value; }
        }
    }
}
